<?php
/*
* Class teia\webdev\php\core\DataPool
* Core class for caching and passing objects between scripts and pages
*
* @author Bernardo Quibiana
* @date created: 20111023
*
* @date modified: 20111023
* @modified: Bernardo Quibiana
*/

// namespace declaration: Core Abstract Data Types
namespace teia\webdev\php\core;

require_once 'Product.inc';

class DataPool {
	static private $product_array = array();
	
	/**
	 * Stores a product
	 * @param teia\webdev\core\Product $product
	 * @return boolean
	 */
	static function push_product($product) {
		if ($product) {
			self::$product_array[$product->id] = $product;
			return true;
		}
		return false;
	}
	
	/**
	 * Enter description here ...
	 * @param string $id
	 * @param boolean $is_item_id
	 * @return Ambigous <NULL, multitype:>
	 */
	static function fetch_product($id, $is_item_id=FALSE) {
		if ($is_item_id) {
			foreach (self::$product_array as $prod) {
				if ($prod->has_item($id)) {
					return $prod;
				}
			}
		} else {	
			return isset(self::$product_array[$id]) ? self::$product_array[$id] : null;
		}
		return NULL;
	}
	
	static function pop_product($id, $is_item_id=FALSE) {
		if ($is_item_id) {
			foreach (self::$product_array as $prod) {
				if ($prod->has_item($id)) {
					unset(self::$product_array[$id]);
					return true;
				}
			}
		} else {
			if (isset(self::$product_array[$id])) {
				unset(self::$product_array[$id]);
				return true;
			}
		}
		return false;
	}
} // end of class DataCache

?>